﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class CourseStudyBLL
    {
        public static IQueryable<CourseStudyInfo> GetList()
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                var re = dal.SelectQueryable(o => true);
                return re;
            }
        }

        public static CourseStudyInfo Get(int id)
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }

        /// <summary>
        /// 根据sectionId和类型获取
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static CourseStudyInfo Get(int id, byte type)
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.SectionId == id && o.Type == type);
                return re;
            }
        }

        public static bool Del(int id)
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }

        public static bool Edit(CourseStudyInfo info)
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                return dal.Update(info) != null;
            }
        }

        public static bool Add(CourseStudyInfo info)
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                return dal.Add(info) != null;
            }
        }

        public static bool Add(IEnumerable<CourseStudyInfo> list)
        {
            using (var dal = new CourseStudyDAL(Settings.ConnectionName))
            {
                return dal.Add(list) != null;
            }
        }
    }
}
